package com.mjlf.mr.speed;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @ClassName: SpeedCombiner
 * @Author: majun
 * @CreateDate: 2018/12/18 11:40
 * @Version: 1.0
 * @Description: TODO
 */

public class SpeedCombiner extends Reducer<Speed, Text, Speed, Text> {

    @Override
    protected void reduce(Speed key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        int flag = 0;
        String carN = "";
        System.out.println("\n\n\n");
        for(Text index : values){
            if(flag == 0){
                carN = index.toString().substring(20, 26);
                context.write(key, index);
                flag ++;
            }else {
                String indexCarN = index.toString().substring(20, 26);
                if(indexCarN.equals(carN)){
                    continue;
                }else {
                    context.write(key, index);
                    break;
                }
            }
        }
    }
}
